package demo;

import org.apache.http.Header;
import org.apache.http.HttpEntity;
import org.apache.http.HttpHost;
import org.apache.http.entity.StringEntity;
import org.apache.http.message.BasicHeader;
import org.apache.http.util.EntityUtils;
import org.elasticsearch.client.Response;
import org.elasticsearch.client.RestClient;

import java.io.IOException;
import java.util.Collections;

/**
 * @author yuyufeng
 * @date 2017/10/30
 */
public class Index {
    public static void main(String[] args) {
        RestClient restClient = RestClient.builder(
                new HttpHost("127.0.0.1", 9200, "http")).build();
        Response response = null;
//        Entire running time(millis)=[518] in http://ota.bababus.com/partner/getRealRegularBuses.htm [distributorCode=1792] [sign=n2WlLymZZaOPJk1ySInGYN14EE4cjN+gQ18HWRWqfhgQEFMUHUp3GyrYbJNIMmTVHdmFwJpSi0SEcdonunvxiWP9LQUh5Z0zsQ+/B9OyvYbpWzu0Hlj5V0V3zvAtfpjMcAo+0ciFkYerE19FbSvLnHwnQVcDzt5XGV/+2MpwSC4=] [data={"body":{"arrivalPlacename":"亭林","departureDate":"2017-06-10","departurePlacename":"柯桥"},"header":{"operateCode":"000","type":"1","version":"1.0"}}]
        try {
            String json = " {\n" +
                    "  \"distributorCode\": \"XCLY\",\n" +
                    "  \"url\":\" http://ota.bababus.com/partner/getRealRegularBuses.htm\",\n" +
                    "    \"sign\":\"TcDDcdjpQOiYKt4OvcmITdkkJxS32FzC75v/prfW8g41K1eNBZO45vKn5Hj34r5I0KCKB3sI+F4d51SfCvf3S5yAEjR4kECqR//XtHjuulQD6qiLA23ut53ELg2z3NkVvfhfIoGBAXK+EUHXrzWnc6Ox90UgRmoHu9ch3L2BOcQ=\",\n" +
                    "     \"data\":{\"header\":{\"version\":\"1.0\",\"type\":\"1\",\"operateCode\":\"000\"},\"body\":{\"departurePlacename\":\"新昌\",\"arrivalPlacename\":\"杭州\",\"departureDate\":\"2017-06-03\"}}\n" +
                    "   \n" +
                    "    }";
            HttpEntity entity = new StringEntity(json,"utf-8");
            Header header = new BasicHeader("referer","http:www.yuyufeng.top");
            response = restClient.performRequest("POST", "/distributor/request", Collections.emptyMap(),entity,header);
            System.out.println(EntityUtils.toString(response.getEntity()));
        } catch (IOException e) {
            e.printStackTrace();
        }finally {
            try {
                restClient.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }


    }
}
